package com.feng.vhr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feng.vhr.mapper.EmployeeMapper;
import com.feng.vhr.mapper.EmpsalaryMapper;
import com.feng.vhr.pojo.Employee;
import com.feng.vhr.pojo.Empsalary;
import com.feng.vhr.response.REmployee;
import com.feng.vhr.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author feng
 * @since 2022-05-09
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private EmpsalaryMapper empsalaryMapper;

    /**
     * 查询所有员工信息
     * @param emp
     * @param beginDateScope
     * @return
     */
    @Override
    public List<REmployee> getAllEmpInfo(Employee emp, Date[] beginDateScope) {
        List<REmployee> allEmpSalaryAndDepartment = employeeMapper.getAllEmpInfo(emp,beginDateScope);
        return allEmpSalaryAndDepartment;
    }

    /**
     * 删除员工资料及对应的账套信息
     * @param id
     * @return
     */
    @Override
    public boolean deleteEmpAndSalary(int id) {
        int i = employeeMapper.deleteById(id);
        QueryWrapper<Empsalary> wrapper = new QueryWrapper<>();
        wrapper.eq("eid",id);
        int delete = empsalaryMapper.delete(wrapper);
        if ((i==1&&delete==1)||i==1){
         return true;
        }
        return false;
    }

    /**
     * 获取最新工号信息
     * @return
     */
    @Override
    public int maxWorkID() {
        int maxWorkID = employeeMapper.maxWorkID();
        return maxWorkID+1;
    }
}
